export default class Score {
    score = 0
    level = 1

    scoreEle: HTMLElement
    levelEle: HTMLElement

    // 设置最高等级
    maxLevel: number

    // 设置每多少分升级
    upScore: number

    constructor(maxLevel: number = 10, upScore: number = 10) {
        this.scoreEle = document.getElementById('score')!
        this.levelEle = document.getElementById('level')!
        this.maxLevel = maxLevel
        this.upScore = upScore
    }

    // 加分
    addScore() {
        this.scoreEle.innerHTML = ++this.score + ''
        if(this.score % this.upScore == 0) {
            this.addLevel()
        }
    }

    // 升级
    addLevel() {
        // 判断是否满级
        if (this.level < this.maxLevel) {
            this.levelEle.innerHTML = ++this.level + ''
        }
    }
}